package tech

func xyCycleGetStrongs(node *ChainNode) []GroupItem {
	cell := node.item.group[0]
	cand := node.item.cand
	cands := cell.cands
	cands.Delete(cand)
	strong := GroupItem{cands.GetList()[0], [9]*Cell{cell}}
	return []GroupItem{strong}
}

func (g *Grid) xyCycleGetWeaks(node *ChainNode) []GroupItem {
	weaks := []GroupItem{}
	for _, cell := range g.candSeenCells(node.item.cand, node.item.group[0]) {
		if cell.cands.Count() != 2 {
			continue
		}
		weak := GroupItem{node.item.cand, [9]*Cell{cell}}
		//if existSingleItemCell(node, weak) {
		//	continue
		//}
		weaks = append(weaks, weak)
	}
	return weaks
}

func (s *Solve) XYCycle3(g *Grid) (used bool, results []*Result) {
	c := Chain{
		g:            g,
		strategyName: "XY-Cycle3",
		getWeaks:     g.xyCycleGetWeaks,
		getStrongs:   xyCycleGetStrongs,
		closeCycle:   metWithWeakLink,
		canRemove:    g.canRemoveSingle,
	}

	return c.ExecStrategy3()
}
